<template>
  <div style="display: inline-block; text-align: left">
    <el-button style="margin-bottom:10px" type="primary" class="buttoncss" icon="el-icon-edit" circle title="编辑" @click="open()"/>
    <el-dialog :visible.sync="dialogTableVisible" title="编辑(不能重复)" @close="close">
      <el-form ref="editData" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
        <el-form-item :label="'角色名称'" prop="name">
          <el-input v-model="editData.name"/>
        </el-form-item>
        <el-form-item :label="'角色标识'" prop="role">
          <el-input v-model="editData.role"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm()">修改</el-button>
          <el-button @click="close()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import '@/styles/buttonStyle.css'
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
import store from '@/store'
import { edit } from '@/api/shop_admin_auth/shopRole'

export default {
  name: 'DragDialogDemo',
  directives: { elDragDialog },
  props: {
    row_data: {
      type: Object,
      default: function() {
        return null
      }
    }
  },
  data() {
    return {
      dialogTableVisible: false,
      editData: {
      }
    }
  },
  created: function() {
    // console.log(this.row_data)
    this.editData = this.row_data
    console.log('data---', this.editData)
  },
  methods: {
    open() {
      this.dialogTableVisible = true
    },
    submitForm() {
      edit(store.getters.token, this.editData).then(res => {
        if (res.data.status === true) {
          this.$message({
            type: 'success',
            message: res.data.msg
          })
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            // 报错提示的时间长点
            // 默认为3000
            duration: 4000
          })
        }
        this.$emit('getLists')
        this.close()
      })
    },
    close() {
      console.log(this.$parent.data)
      this.$emit('getLists')
      this.dialogTableVisible = false
    }
  }
}
</script>
